<?php
/*
 * MiniMe - a minimalistic OStatus complient microblogging tool
 * Copyright (C) 2010, Tuomas Koski - koski.tuomas@gmail.com
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * @author     Tuomas Koski <koski.tuomas@gmail.com>
 * @copyright  Tuomas Koski
 * @license    http://www.gnu.org/licenses/lgpl.txt
 */

$basedir = dirname(__FILE__);
require_once $basedir . '/../../../classes/atom.php';
require_once $basedir . '/../../../classes/atom/feed.php';
require_once $basedir . '/../../../classes/atom/childelement.php';

require_once $basedir . '/../../../classes/atom/feed/id.php';
require_once $basedir . '/../../../classes/atom/feed/title.php';
require_once $basedir . '/../../../classes/atom/feed/subtitle.php';
require_once $basedir . '/../../../classes/atom/feed/updated.php';
require_once $basedir . '/../../../classes/atom/feed/logo.php';
require_once $basedir . '/../../../classes/atom/feed/generator.php';
require_once $basedir . '/../../../classes/atom/feed/link.php';
require_once $basedir . '/../../../classes/atom/feed/link/alternatehtml.php';
require_once $basedir . '/../../../classes/atom/feed/link/hub.php';
require_once $basedir . '/../../../classes/atom/feed/link/self.php';
require_once $basedir . '/../../../classes/atom/feed/link/salmon.php';
require_once $basedir . '/../../../classes/atom/feed/link/avatar.php';

require_once $basedir . '/../../../classes/atom/feed/author.php';
require_once $basedir . '/../../../classes/atom/feed/author/uri.php';
require_once $basedir . '/../../../classes/atom/feed/author/name.php';

require_once $basedir . '/../../../classes/activitystream.php';
require_once $basedir . '/../../../classes/activitystream/subject.php';
require_once $basedir . '/../../../classes/activitystream/object.php';
require_once $basedir . '/../../../classes/activitystream/objecttype.php';
require_once $basedir . '/../../../classes/activitystream/verb.php';

require_once $basedir . '/../../../classes/atom.php';
require_once $basedir . '/../../../classes/atom/childelement.php';
require_once $basedir . '/../../../classes/atom/entry.php';

require_once $basedir . '/../../../classes/atom/entry/id.php';
require_once $basedir . '/../../../classes/atom/entry/content.php';
require_once $basedir . '/../../../classes/atom/entry/title.php';
require_once $basedir . '/../../../classes/atom/entry/updated.php';
require_once $basedir . '/../../../classes/atom/entry/link.php';
require_once $basedir . '/../../../classes/atom/entry/link/alternatehtml.php';
require_once $basedir . '/../../../classes/atom/entry/link/avatar.php';
require_once $basedir . '/../../../classes/atom/entry/link/photo.php';
require_once $basedir . '/../../../classes/atom/entry/author/link/photo.php';

require_once $basedir . '/../../../classes/atom/entry/author.php';
require_once $basedir . '/../../../classes/atom/entry/author/uri.php';
require_once $basedir . '/../../../classes/atom/entry/author/name.php';

require_once $basedir . '/../../../classes/activitystream.php';
require_once $basedir . '/../../../classes/activitystream/actor.php';
require_once $basedir . '/../../../classes/activitystream/objecttype.php';
require_once $basedir . '/../../../classes/activitystream/verb.php';

require_once $basedir . '/../../../classes/thr.php';
require_once $basedir . '/../../../classes/thr/inreplyto.php';

require_once $basedir . '/../../../classes/minime/hrefrenderer.php';

class Atom_FeedTest extends PHPUnit_Framework_TestCase {
    
    public function testConstructorOfEntryObject() {
        $object = new Atom_Feed();
        $this->assertEquals("Atom_Feed", get_class($object));
    }
    
   public function testCreationOfFullAtomFeed() {
        date_default_timezone_set('Europe/Berlin');
        
        // Let's create the needed elements.
        $generator = new Atom_Feed_Generator("http://madebymonsieur.com", "MiniMe - Life to XML");
        $id = new Atom_Feed_Id("http://www.lobstermonster.org/tuomas");
		$title = new Atom_Feed_Title("This is a magic feed!");
		$subtitle = new Atom_Feed_Subtitle("Very amazing feed!");
		$logo = new Atom_Feed_Logo("http://www.example.com/logo.png");
		$updated = new Atom_Feed_Updated('2010-07-21T23:25:59+00:00');
		
		$author = new Atom_Feed_Author();
		$author->addChildElement(new Atom_Feed_Author_Name('Tuomas Koski'));
		$author->addChildElement(new Atom_Feed_Author_Uri('http://www.lobstermonster.org/tuomas'));
		
		
		// Let's create the activity actor
		$as_subject = new Activitystream_Subject();
		$as_subject->addChildElement(new Activitystream_ObjectType(Activitystream_ObjectType::TYPE_PERSON));
		
		$as_subject->addChildElement(new Atom_Feed_Id("tuomas@lobstermonster.org"));
		$as_subject->addChildElement(new Atom_Feed_Title("Tuomas Koski"));
		$as_subject->addChildElement(new Atom_Feed_Link(Atom_Feed_Link::REL_ALTERNATE, 
		                                               Atom_Feed_Link::TYPE_TEXTHTML, 
		                                               'http://www.lobstermonster.org/tuomas'));
		
        // Finally let's create the Atom Entry itself
		$atom = new Atom_Feed();
		
	    $atom->addChildElement($generator);
		$atom->addChildElement($id);
		$atom->addChildElement($title);
		$atom->addChildElement($subtitle);
		$atom->addChildElement($logo);
		$atom->addChildElement($updated);
		$atom->addChildElement($author);
		
		$atom->addChildElement(new Atom_Feed_Link_AlternateHtml("http://www.lobstermonster.org/tuomas"));
		$atom->addChildElement(new Atom_Feed_Link_Hub("http://www.lobstermonster.org/minime/hub.php"));
		$atom->addChildElement(new Atom_Feed_Link_Salmon("http://www.lobstermonster.org/minime/salmon/tuomas"));
		$atom->addChildElement(new Atom_Feed_Link_Self("http://www.lobstermonster.org/minime/atom/tuomas"));
		
		$atom->addChildElement($as_subject);
		
		// Let's add needed new namespaces.
		$atom->addNamespace(ActivityStream::AS_NS_PREFIX, Activitystream::AS_NS);
		
		$expected = '<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:activity="http://activitystrea.ms/spec/1.0/">
  <generator uri="http://madebymonsieur.com" version="0.0.1">MiniMe - Life to XML</generator>
  <id>http://www.lobstermonster.org/tuomas</id>
  <title>This is a magic feed!</title>
  <subtitle>Very amazing feed!</subtitle>
  <logo>http://www.example.com/logo.png</logo>
  <updated>2010-07-21T23:25:59+00:00</updated>
  <author>
    <name>Tuomas Koski</name>
    <uri>http://www.lobstermonster.org/tuomas</uri>
  </author>
  <link rel="alternate" type="text/html" href="http://www.lobstermonster.org/tuomas"/>
  <link rel="hub" href="http://www.lobstermonster.org/minime/hub.php"/>
  <link rel="http://salmon-protocol.org/ns/salmon-replies" href="http://www.lobstermonster.org/minime/salmon/tuomas"/>
  <link rel="self" type="application/atom+xml" href="http://www.lobstermonster.org/minime/atom/tuomas"/>
  <activity:subject>
    <activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
    <id>tuomas@lobstermonster.org</id>
    <title>Tuomas Koski</title>
    <link rel="alternate" type="text/html" href="http://www.lobstermonster.org/tuomas"/>
  </activity:subject>
</feed>
';
		$this->assertEquals($expected, $atom->asXML());
    }

    public function testUpdateOfEmptyAtomFeed() {
        date_default_timezone_set('Europe/Berlin');
        
        // Let's create the needed elements.
        $generator = new Atom_Feed_Generator("http://madebymonsieur.com", "MiniMe - Life to XML");
        $id = new Atom_Feed_Id("http://www.lobstermonster.org/tuomas");
        $title = new Atom_Feed_Title("This is a magic feed!");
        $subtitle = new Atom_Feed_Subtitle("Very amazing feed!");
        $logo = new Atom_Feed_Logo("http://www.example.com/logo.png");
        $updated = new Atom_Feed_Updated('2010-07-21T23:25:59+00:00');
        
        $author = new Atom_Feed_Author();
        $author->addChildElement(new Atom_Feed_Author_Name('Tuomas Koski'));
        $author->addChildElement(new Atom_Feed_Author_Uri('http://www.lobstermonster.org/tuomas'));
        
        
        // Let's create the activity actor
        $as_subject = new Activitystream_Subject();
        $as_subject->addChildElement(new Activitystream_ObjectType(Activitystream_ObjectType::TYPE_PERSON));
        
        $as_subject->addChildElement(new Atom_Feed_Id("tuomas@lobstermonster.org"));
        $as_subject->addChildElement(new Atom_Feed_Title("Tuomas Koski"));
        $as_subject->addChildElement(new Atom_Feed_Link(Atom_Feed_Link::REL_ALTERNATE, 
                                                       Atom_Feed_Link::TYPE_TEXTHTML, 
                                                       'http://www.lobstermonster.org/tuomas'));
        
        // Finally let's create the Atom Entry itself
        $atom = new Atom_Feed();
        
        $atom->addChildElement($generator);
        $atom->addChildElement($id);
        $atom->addChildElement($title);
        $atom->addChildElement($subtitle);
        $atom->addChildElement($logo);
        $atom->addChildElement($updated);
        $atom->addChildElement($author);
        
        $atom->addChildElement(new Atom_Feed_Link_AlternateHtml("http://www.lobstermonster.org/tuomas"));
        $atom->addChildElement(new Atom_Feed_Link_Hub("http://www.lobstermonster.org/minime/hub.php"));
        $atom->addChildElement(new Atom_Feed_Link_Salmon("http://www.lobstermonster.org/minime/salmon/tuomas"));
        $atom->addChildElement(new Atom_Feed_Link_Self("http://www.lobstermonster.org/minime/atom/tuomas"));
        
        $atom->addChildElement($as_subject);
        
        // Let's add needed new namespaces.
        $atom->addNamespace(ActivityStream::AS_NS_PREFIX, Activitystream::AS_NS);
        
        # Let's create a Atom
        // Let's create the needed elements.
        $idE = new Atom_Entry_Id("mimime:12345689");
        $titleE = new Atom_Entry_Title("Tuomas is now following Pamela Anderson");
        $contentE = new Atom_Entry_Content("Tuomas is now following Pamela Anderson", 
                                          Atom_Entry_Content::TYPE_TEXTHTML);
        $updatedE = new Atom_Entry_Updated('2010-07-26T06:42:55+02:00');
        
        $authorE = new Atom_Entry_Author();
        $authorE->addChildElement(new Atom_Entry_Author_Uri('http://lobstermonster.org/tuomas'));
        $authorE->addChildElement(new Atom_Entry_Author_Name('Tuomas Koski'));
        
        // Let's create the activity actor
        $as_actorE = new Activitystream_Actor();
        $as_actorE->addChildElement(new Activitystream_ObjectType(Activitystream_ObjectType::TYPE_PERSON));
        
        $as_actorE->addChildElement(new Atom_Entry_Id("tuomas@lobstermonster.org"));
        $as_actorE->addChildElement(new Atom_Entry_Title("Tuomas Koski"));
        $as_actorE->addChildElement(new Atom_Entry_Link(Atom_Entry_Link::REL_ALTERNATE, 
                                                       Atom_Entry_Link::TYPE_TEXTHTML, 
                                                       'http://identi.ca/tkoski'));
        
        // And let's create the activity verb
        $as_verbE = new Activitystream_Verb(Activitystream_Verb::VERB_FOLLOW);

        // Finally let's create the Atom Entry itself
        $atomE = new Atom_Entry();
        
        $atomE->addChildElement($idE);
        $atomE->addChildElement($titleE);
        $atomE->addChildElement($contentE);
        $atomE->addChildElement($updatedE);
        $atomE->addChildElement($authorE);
        $atomE->addChildElement($as_actorE);
        $atomE->addChildElement($as_verbE);
        
        // Let's add needed new namespaces.
        $atomE->addNamespace(ActivityStream::AS_NS_PREFIX, Activitystream::AS_NS);
        
        $expected = '<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:activity="http://activitystrea.ms/spec/1.0/">
  <generator uri="http://madebymonsieur.com" version="0.0.1">MiniMe - Life to XML</generator>
  <id>http://www.lobstermonster.org/tuomas</id>
  <title>This is a magic feed!</title>
  <subtitle>Very amazing feed!</subtitle>
  <logo>http://www.example.com/logo.png</logo>
  <updated>2010-07-21T23:25:59+00:00</updated>
  <author>
    <name>Tuomas Koski</name>
    <uri>http://www.lobstermonster.org/tuomas</uri>
  </author>
  <link rel="alternate" type="text/html" href="http://www.lobstermonster.org/tuomas"/>
  <link rel="hub" href="http://www.lobstermonster.org/minime/hub.php"/>
  <link rel="http://salmon-protocol.org/ns/salmon-replies" href="http://www.lobstermonster.org/minime/salmon/tuomas"/>
  <link rel="self" type="application/atom+xml" href="http://www.lobstermonster.org/minime/atom/tuomas"/>
  <activity:subject>
    <activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
    <id>tuomas@lobstermonster.org</id>
    <title>Tuomas Koski</title>
    <link rel="alternate" type="text/html" href="http://www.lobstermonster.org/tuomas"/>
  </activity:subject>
  <entry>
    <id>mimime:12345689</id>
    <title>Tuomas is now following Pamela Anderson</title>
    <content type="text/html">Tuomas is now following Pamela Anderson</content>
    <updated>2010-07-26T06:42:55+02:00</updated>
    <author>
      <uri>http://lobstermonster.org/tuomas</uri>
      <name>Tuomas Koski</name>
    </author>
    <activity:actor>
      <activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
      <id>tuomas@lobstermonster.org</id>
      <title>Tuomas Koski</title>
      <link rel="alternate" type="text/html" href="http://identi.ca/tkoski"/>
    </activity:actor>
    <activity:verb>http://activitystrea.ms/schema/1.0/follow</activity:verb>
  </entry>
</feed>
';
        
        $atom->addChildElement($atomE);
        
        //echo $atom->asXML();
        
        $this->assertEquals($expected, $atom->asXML());   
    }
    
    public function testAddingAtomToFeed() {
        $rawXml = '<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:activity="http://activitystrea.ms/spec/1.0/">
  <generator uri="http://madebymonsieur.com" version="0.0.1">MiniMe - Life to XML</generator>
  <id>http://www.lobstermonster.org/tuomas</id>
  <title>This is a magic feed!</title>
  <subtitle>Very amazing feed!</subtitle>
  <logo>http://www.example.com/logo.png</logo>
  <updated>2010-07-21T23:25:59+00:00</updated>
  <author>
    <name>Tuomas Koski</name>
    <uri>http://www.lobstermonster.org/tuomas</uri>
  </author>
  <link rel="alternate" type="text/html" href="http://www.lobstermonster.org/tuomas"/>
  <link rel="hub" href="http://www.lobstermonster.org/minime/hub.php"/>
  <link rel="http://salmon-protocol.org/ns/salmon-replies" href="http://www.lobstermonster.org/minime/salmon/tuomas"/>
  <link rel="self" type="application/atom+xml" href="http://www.lobstermonster.org/minime/atom/tuomas"/>
  <activity:subject>
    <activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
    <id>tuomas@lobstermonster.org</id>
    <title>Tuomas Koski</title>
    <link rel="alternate" type="text/html" href="http://www.lobstermonster.org/tuomas"/>
  </activity:subject>
  <entry>
    <id>mimime:12345689</id>
    <title>Tuomas is now following Pamela Anderson</title>
    <content type="text/html">Tuomas is now following Pamela Anderson</content>
    <updated>2010-07-26T06:42:55+02:00</updated>
    <author>
      <uri>http://lobstermonster.org/tuomas</uri>
      <name>Tuomas Koski</name>
    </author>
    <activity:actor>
      <activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
      <id>tuomas@lobstermonster.org</id>
      <title>Tuomas Koski</title>
      <link rel="alternate" type="text/html" href="http://identi.ca/tkoski"/>
    </activity:actor>
    <activity:verb>http://activitystrea.ms/schema/1.0/follow</activity:verb>
  </entry>
</feed>
';
        
        $post = '<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:activity="http://activitystrea.ms/spec/1.0/">
  <generator uri="http://madebymonsieur.com" version="0.0.1">MiniMe - Life to XML</generator>
  <id>post 1</id>
  <title>title 1</title>
  <subtitle>Subtitle 1</subtitle>
  <logo>http://www.example.com/logo.png</logo>
  <updated>2010-07-22T23:25:59+00:00</updated>
  <author>
    <name>Pamela A</name>
    <uri>http://www.lobstermonster.org/Pamela</uri>
  </author>
  <link rel="alternate" type="text/html" href="http://www.lobstermonster.org/pamela"/>
  <link rel="hub" href="http://www.lobstermonster.org/minime/hub.php"/>
  <link rel="http://salmon-protocol.org/ns/salmon-replies" href="http://www.lobstermonster.org/minime/salmon/pamela"/>
  <link rel="self" type="application/atom+xml" href="http://www.lobstermonster.org/minime/atom/pamela"/>
  <activity:subject>
    <activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
    <id>pamela@lobstermonster.org</id>
    <title>Pamela A</title>
    <link rel="alternate" type="text/html" href="http://www.lobstermonster.org/pamela"/>
  </activity:subject>
  <entry>
    <id>mimime:12345689</id>
    <title>Hey! What\'s up?</title>
    <content type="text/html">Hey! What\'s up?</content>
    <updated>2010-07-28T06:42:55+02:00</updated>
    <author>
      <uri>http://lobstermonster.org/pamela</uri>
      <name>Pamela A</name>
    </author>
    <activity:actor>
      <activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
      <id>pamela@lobstermonster.org</id>
      <title>Pamela A</title>
      <link rel="alternate" type="text/html" href="http://identi.ca/pamela"/>
    </activity:actor>
    <activity:verb>http://activitystrea.ms/schema/1.0/post</activity:verb>
  </entry>
</feed>
';
        
        $expected = '<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:activity="http://activitystrea.ms/spec/1.0/">
  <generator uri="http://madebymonsieur.com" version="0.0.1">MiniMe - Life to XML</generator>
  <id>http://www.lobstermonster.org/tuomas</id>
  <title>This is a magic feed!</title>
  <subtitle>Very amazing feed!</subtitle>
  <logo>http://www.example.com/logo.png</logo>
  <updated>2010-07-22T23:25:59+00:00</updated>
  <author>
    <name>Tuomas Koski</name>
    <uri>http://www.lobstermonster.org/tuomas</uri>
  </author>
  <link rel="alternate" type="text/html" href="http://www.lobstermonster.org/tuomas"/>
  <link rel="hub" href="http://www.lobstermonster.org/minime/hub.php"/>
  <link rel="http://salmon-protocol.org/ns/salmon-replies" href="http://www.lobstermonster.org/minime/salmon/tuomas"/>
  <link rel="self" type="application/atom+xml" href="http://www.lobstermonster.org/minime/atom/tuomas"/>
  <activity:subject>
    <activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
    <id>tuomas@lobstermonster.org</id>
    <title>Tuomas Koski</title>
    <link rel="alternate" type="text/html" href="http://www.lobstermonster.org/tuomas"/>
  </activity:subject>
  <entry>
    <id>mimime:12345689</id>
    <title>Hey! What\'s up?</title>
    <content type="text/html">Hey! What\'s up?</content>
    <updated>2010-07-28T06:42:55+02:00</updated>
    <author>
      <uri>http://lobstermonster.org/pamela</uri>
      <name>Pamela A</name>
    </author>
    <activity:actor>
      <activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
      <id>pamela@lobstermonster.org</id>
      <title>Pamela A</title>
      <link rel="alternate" type="text/html" href="http://identi.ca/pamela"/>
    </activity:actor>
    <activity:verb>http://activitystrea.ms/schema/1.0/post</activity:verb>
  </entry><entry>
    <id>mimime:12345689</id>
    <title>Tuomas is now following Pamela Anderson</title>
    <content type="text/html">Tuomas is now following Pamela Anderson</content>
    <updated>2010-07-26T06:42:55+02:00</updated>
    <author>
      <uri>http://lobstermonster.org/tuomas</uri>
      <name>Tuomas Koski</name>
    </author>
    <activity:actor>
      <activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
      <id>tuomas@lobstermonster.org</id>
      <title>Tuomas Koski</title>
      <link rel="alternate" type="text/html" href="http://identi.ca/tkoski"/>
    </activity:actor>
    <activity:verb>http://activitystrea.ms/schema/1.0/follow</activity:verb>
  </entry>
</feed>
';
        
        $doc = new DOMDocument();
        $doc->loadXML($rawXml);
        
        $push = new DOMDocument();
        $push->loadXML($post);
        
        $newEntry = $doc->importNode($push->getElementsByTagName("entry")->item(0), true);
        
        $doc->getElementsByTagName("feed")->item(0)->insertBefore($newEntry, $doc->getElementsByTagName("entry")->item(0));
        
        $doc->getElementsByTagName("feed")->item(0)->getElementsByTagName("updated")->item(0)->nodeValue = "2010-07-22T23:25:59+00:00";
        
        $this->assertEquals($expected, $doc->saveXML());
    }
    
    public function testUpdateOfFilledAtomFeed() {
        date_default_timezone_set('Europe/Berlin');
        
        // Let's create the needed elements.
        $generator = new Atom_Feed_Generator("http://madebymonsieur.com", "MiniMe - Life to XML");
        $id = new Atom_Feed_Id("http://www.lobstermonster.org/tuomas");
        $title = new Atom_Feed_Title("This is a magic feed! Updated!");
        $subtitle = new Atom_Feed_Subtitle("Very amazing feed!");
        $logo = new Atom_Feed_Logo("http://www.example.com/logo.png");
        $updated = new Atom_Feed_Updated('2010-07-29T23:25:59+00:00');
        
        $author = new Atom_Feed_Author();
        $author->addChildElement(new Atom_Feed_Author_Name('Tuomas Koski'));
        $author->addChildElement(new Atom_Feed_Author_Uri('http://www.lobstermonster.org/tuomas'));
        
        
        // Let's create the activity actor
        $as_subject = new Activitystream_Subject();
        $as_subject->addChildElement(new Activitystream_ObjectType(Activitystream_ObjectType::TYPE_PERSON));
        
        $as_subject->addChildElement(new Atom_Feed_Id("tuomas@lobstermonster.org"));
        $as_subject->addChildElement(new Atom_Feed_Title("Tuomas Koski"));
        $as_subject->addChildElement(new Atom_Feed_Link(Atom_Feed_Link::REL_ALTERNATE, 
                                                       Atom_Feed_Link::TYPE_TEXTHTML, 
                                                       'http://www.lobstermonster.org/tuomas'));
        
        // Finally let's create the Atom Entry itself
        $atom = new Atom_Feed();
        
        $atom->addChildElement($generator);
        $atom->addChildElement($id);
        $atom->addChildElement($title);
        $atom->addChildElement($subtitle);
        $atom->addChildElement($logo);
        $atom->addChildElement($updated);
        $atom->addChildElement($author);
        
        $atom->addChildElement(new Atom_Feed_Link_AlternateHtml("http://www.lobstermonster.org/tuomas"));
        $atom->addChildElement(new Atom_Feed_Link_Hub("http://www.lobstermonster.org/minime/hub.php"));
        $atom->addChildElement(new Atom_Feed_Link_Salmon("http://www.lobstermonster.org/minime/salmon/tuomas"));
        $atom->addChildElement(new Atom_Feed_Link_Self("http://www.lobstermonster.org/minime/atom/tuomas"));
        
        $atom->addChildElement($as_subject);
        
        // Let's add needed new namespaces.
        $atom->addNamespace(ActivityStream::AS_NS_PREFIX, Activitystream::AS_NS);

        $rawXml = '<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:activity="http://activitystrea.ms/spec/1.0/">
  <generator uri="http://madebymonsieur.com" version="0.0.1">MiniMe - Life to XML</generator>
  <id>http://www.lobstermonster.org/tuomas</id>
  <title>This is a magic feed!</title>
  <subtitle>Very amazing feed!</subtitle>
  <logo>http://www.example.com/logo.png</logo>
  <updated>2010-07-21T23:25:59+00:00</updated>
  <author>
    <name>Tuomas Koski</name>
    <uri>http://www.lobstermonster.org/tuomas</uri>
  </author>
  <link rel="alternate" type="text/html" href="http://www.lobstermonster.org/tuomas"/>
  <link rel="hub" href="http://www.lobstermonster.org/minime/hub.php"/>
  <link rel="http://salmon-protocol.org/ns/salmon-replies" href="http://www.lobstermonster.org/minime/salmon/tuomas"/>
  <link rel="self" type="application/atom+xml" href="http://www.lobstermonster.org/minime/atom/tuomas"/>
  <activity:subject>
    <activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
    <id>tuomas@lobstermonster.org</id>
    <title>Tuomas Koski</title>
    <link rel="alternate" type="text/html" href="http://www.lobstermonster.org/tuomas"/>
  </activity:subject>
  <entry>
    <id>mimime:12345689</id>
    <title>Hey! What\'s up?</title>
    <content type="text/html">Hey! What\'s up?</content>
    <updated>2010-07-28T06:42:55+02:00</updated>
    <author>
      <uri>http://lobstermonster.org/tuomas</uri>
      <name>Tuomas Koski</name>
    </author>
    <activity:actor>
      <activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
      <id>pamela@lobstermonster.org</id>
      <title>Pamela A</title>
      <link rel="alternate" type="text/html" href="http://identi.ca/palema"/>
    </activity:actor>
    <activity:verb>http://activitystrea.ms/schema/1.0/post</activity:verb>
  </entry><entry>
    <id>mimime:12345689</id>
    <title>Tuomas is now following Pamela Anderson</title>
    <content type="text/html">Tuomas is now following Pamela Anderson</content>
    <updated>2010-07-26T06:42:55+02:00</updated>
    <author>
      <uri>http://lobstermonster.org/tuomas</uri>
      <name>Tuomas Koski</name>
    </author>
    <activity:actor>
      <activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
      <id>tuomas@lobstermonster.org</id>
      <title>Tuomas Koski</title>
      <link rel="alternate" type="text/html" href="http://identi.ca/tkoski"/>
    </activity:actor>
    <activity:verb>http://activitystrea.ms/schema/1.0/follow</activity:verb>
  </entry>
</feed>';
        
        $expected = '<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:activity="http://activitystrea.ms/spec/1.0/">
  <generator uri="http://madebymonsieur.com" version="0.0.1">MiniMe - Life to XML</generator>
  <id>http://www.lobstermonster.org/tuomas</id>
  <title>This is a magic feed! Updated!</title>
  <subtitle>Very amazing feed!</subtitle>
  <logo>http://www.example.com/logo.png</logo>
  <updated>2010-07-29T23:25:59+00:00</updated>
  <author>
    <name>Tuomas Koski</name>
    <uri>http://www.lobstermonster.org/tuomas</uri>
  </author>
  <link rel="alternate" type="text/html" href="http://www.lobstermonster.org/tuomas"/>
  <link rel="hub" href="http://www.lobstermonster.org/minime/hub.php"/>
  <link rel="http://salmon-protocol.org/ns/salmon-replies" href="http://www.lobstermonster.org/minime/salmon/tuomas"/>
  <link rel="self" type="application/atom+xml" href="http://www.lobstermonster.org/minime/atom/tuomas"/>
  <activity:subject>
    <activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
    <id>tuomas@lobstermonster.org</id>
    <title>Tuomas Koski</title>
    <link rel="alternate" type="text/html" href="http://www.lobstermonster.org/tuomas"/>
  </activity:subject>
  <entry>
    <id>mimime:12345689</id>
    <title>Hey! What\'s up?</title>
    <content type="text/html">Hey! What\'s up?</content>
    <updated>2010-07-28T06:42:55+02:00</updated>
    <author>
      <uri>http://lobstermonster.org/tuomas</uri>
      <name>Tuomas Koski</name>
    </author>
    <activity:actor>
      <activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
      <id>pamela@lobstermonster.org</id>
      <title>Pamela A</title>
      <link rel="alternate" type="text/html" href="http://identi.ca/palema"/>
    </activity:actor>
    <activity:verb>http://activitystrea.ms/schema/1.0/post</activity:verb>
  </entry>
  <entry>
    <id>mimime:12345689</id>
    <title>Tuomas is now following Pamela Anderson</title>
    <content type="text/html">Tuomas is now following Pamela Anderson</content>
    <updated>2010-07-26T06:42:55+02:00</updated>
    <author>
      <uri>http://lobstermonster.org/tuomas</uri>
      <name>Tuomas Koski</name>
    </author>
    <activity:actor>
      <activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
      <id>tuomas@lobstermonster.org</id>
      <title>Tuomas Koski</title>
      <link rel="alternate" type="text/html" href="http://identi.ca/tkoski"/>
    </activity:actor>
    <activity:verb>http://activitystrea.ms/schema/1.0/follow</activity:verb>
  </entry>
</feed>
';
        
        $doc = new DOMDocument();
        $doc->loadXML($rawXml);
        foreach ($doc->getElementsByTagName("entry") as $entry) {
            $atom->addDOMElement($entry);
        }
        
        $this->assertEquals($expected, $atom->asXML());
    }
    
    public function testAddingIdenticaPush() {
        $fromIdentica = '<?xml version="1.0" encoding="UTF-8"?>
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:georss="http://www.georss.org/georss" xmlns:activity="http://activitystrea.ms/spec/1.0/" xmlns:media="http://purl.org/syndication/atommedia" xmlns:poco="http://portablecontacts.net/spec/1.0" xmlns:ostatus="http://ostatus.org/schema/1.0" xmlns:statusnet="http://status.net/schema/api/1/">
 <generator uri="http://status.net" version="0.9.3">StatusNet</generator>
 <id>http://identi.ca/api/statuses/user_timeline/209172.atom</id>
 <title>testkoski timeline</title>
 <subtitle>Updates from testkoski on Identi.ca!</subtitle>
 <logo>http://theme.status.net/0.9.3/identica/default-avatar-profile.png</logo>
 <updated>2010-08-04T08:28:27+00:00</updated>
<author>
 <name>testkoski</name>
 <uri>http://identi.ca/user/209172</uri>
</author>
 <link href="http://identi.ca/testkoski" rel="alternate" type="text/html"/>
 <link href="http://identi.ca/main/sup#209172" rel="http://api.friendfeed.com/2008/03#sup" type="application/json"/>
 <link href="http://identi.ca/main/push/hub" rel="hub"/>
 <link href="http://identi.ca/main/salmon/user/209172" rel="http://salmon-protocol.org/ns/salmon-replies"/>
 <link href="http://identi.ca/main/salmon/user/209172" rel="http://salmon-protocol.org/ns/salmon-mention"/>
 <link href="http://identi.ca/api/statuses/user_timeline/209172.atom" rel="self" type="application/atom+xml"/>
<activity:subject>
 <activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
 <id>http://identi.ca/user/209172</id>
 <title>Tester Koski</title>
 <link rel="alternate" type="text/html" href="http://identi.ca/testkoski"/>
 <link rel="avatar" type="image/png" media:width="96" media:height="96" href="http://theme.status.net/0.9.3/identica/default-avatar-profile.png"/>
 <link rel="avatar" type="image/png" media:width="48" media:height="48" href="http://theme.status.net/0.9.3/identica/default-avatar-stream.png"/>
 <link rel="avatar" type="image/png" media:width="24" media:height="24" href="http://theme.status.net/0.9.3/identica/default-avatar-mini.png"/>
<poco:preferredUsername>testkoski</poco:preferredUsername>
<poco:displayName>Tester Koski</poco:displayName>
</activity:subject>
<entry>
 <title>Test.</title>
 <link rel="alternate" type="text/html" href="http://identi.ca/notice/44997825"/>
 <id>http://identi.ca/notice/44997825</id>
 <published>2010-08-04T08:28:08+00:00</published>
 <updated>2010-08-04T08:28:08+00:00</updated>
 <statusnet:notice_info local_id="44997825" source="web"></statusnet:notice_info>
 <link rel="ostatus:conversation" href="http://identi.ca/conversation/44677429"/>
 <content type="html">Test.</content>
 <georss:point>48.8601 2.3507</georss:point>
</entry>
</feed>';
        
        $minimefeed = '<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:activity="http://activitystrea.ms/spec/1.0/" xmlns:thr="http://purl.org/syndication/thread/1.0">
  <generator uri="http://madebymonsieur.com" version="0.0.1">MiniMe - Life to XML</generator>
  <id>http://localhost/index.php?controller=profile&amp;username=user-c</id>
  <title>User C\'s Microblog</title>
  <subtitle>C Stuff</subtitle>
  <logo></logo>
  <updated>2010-08-04T09:41:16+02:00</updated>
  <author>
    <name>User C</name>
    <uri>http://localhost/index.php?controller=profile&amp;username=user-c</uri>
  </author>
  <link rel="alternate" type="text/html" href="http://localhost/index.php?controller=profile&amp;amp;username=user-c"/>
  <link rel="hub" href="http://localhost/index.php?controller=hub"/>
  <link rel="http://salmon-protocol.org/ns/salmon-replies" href="http://localhost/index.php?controller=salmon&amp;username=user-c"/>
  <link rel="self" type="application/atom+xml" href="http://localhost/index.php?controller=atom&amp;username=user-c"/>
  <activity:subject>
    <activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
    <id>http://localhost/index.php?controller=profile&amp;username=user-c</id>
    <title>User C</title>
    <link rel="alternate" type="text/html" href="http://localhost/index.php?controller=profile&amp;amp;username=user-c"/>
  </activity:subject>
</feed>';
        
        $identica = Atom_Feed::buildFromRawXML($fromIdentica);
        $minime = Atom_Feed::buildFromRawXML($minimefeed);
        
        //$this->assertEquals($fromIdentica, $identica->asXML());
        foreach($identica->getEntries() as $entry) {
            $minime->addChildElement($entry);
        }
        
        $expected= '<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:activity="http://activitystrea.ms/spec/1.0/" xmlns:thr="http://purl.org/syndication/thread/1.0">
  <generator uri="http://madebymonsieur.com" version="0.0.1">MiniMe - Life to XML</generator>
  <id>http://localhost/index.php?controller=profile&amp;username=user-c</id>
  <title>User C\'s Microblog</title>
  <subtitle>C Stuff</subtitle>
  <logo></logo>
  <updated>2010-08-04T09:41:16+02:00</updated>
  <author>
    <name>User C</name>
    <uri>http://localhost/index.php?controller=profile&amp;username=user-c</uri>
  </author>
  <link rel="alternate" type="text/html" href="http://localhost/index.php?controller=profile&amp;amp;username=user-c"/>
  <link rel="hub" href="http://localhost/index.php?controller=hub"/>
  <link rel="http://salmon-protocol.org/ns/salmon-replies" href="http://localhost/index.php?controller=salmon&amp;username=user-c"/>
  <link rel="self" type="application/atom+xml" href="http://localhost/index.php?controller=atom&amp;username=user-c"/>
  <activity:subject>
    <activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
    <id>http://localhost/index.php?controller=profile&amp;username=user-c</id>
    <title>User C</title>
    <link rel="alternate" type="text/html" href="http://localhost/index.php?controller=profile&amp;amp;username=user-c"/>
  </activity:subject>
  <entry>
    <id>http://identi.ca/notice/44997825</id>
    <link rel="alternate" type="text/html" href="http://identi.ca/notice/44997825"/>
    <updated>2010-08-04T08:28:08+00:00</updated>
    <title>Test.</title>
    <content type="html">Test.</content>
    <author>
      <name>testkoski</name>
      <uri>http://identi.ca/user/209172</uri>
    </author>
  </entry>
</feed>
';
        $this->assertEquals($expected, $minime->asXML());
    }
    
    public function testAddEntryLikeABlogPost() {
        $rawXML = '<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:activity="http://activitystrea.ms/spec/1.0/">
  <generator uri="http://madebymonsieur.com" version="0.0.1">MiniMe - Life to XML</generator>
  <id>http://localhost/index.php?controller=profile&amp;username=user-c</id>
  <title>User C\'s Microblog</title>
  <subtitle>C Stuff</subtitle>
  <logo></logo>
  <updated>2010-08-04T09:41:16+02:00</updated>
  <author>
    <name>User C</name>
    <uri>http://localhost/index.php?controller=profile&amp;username=user-c</uri>
  </author>
  <link rel="alternate" type="text/html" href="http://localhost/index.php?controller=profile&amp;amp;username=user-c"/>
  <link rel="hub" href="http://localhost/index.php?controller=hub"/>
  <link rel="http://salmon-protocol.org/ns/salmon-replies" href="http://localhost/index.php?controller=salmon&amp;username=user-c"/>
  <link rel="self" type="application/atom+xml" href="http://localhost/index.php?controller=atom&amp;username=user-c"/>
  <activity:subject>
    <activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
    <id>http://localhost/index.php?controller=profile&amp;username=user-c</id>
    <title>User C</title>
    <link rel="alternate" type="text/html" href="http://localhost/index.php?controller=profile&amp;amp;username=user-c"/>
  </activity:subject>
  <entry>
    <id>http://identi.ca/notice/44997825</id>
    <link rel="alternate" type="text/html" href="http://identi.ca/notice/44997825"/>
    <updated>2010-08-04T08:28:08+00:00</updated>
    <title>Test.</title>
    <content type="html">Test.</content>
    <author>
      <name>testkoski</name>
      <uri>http://identi.ca/user/209172</uri>
    </author>
    <activity:actor>
      <activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
      <id>http://www.lobstermonster.org/profile/koski</id>
      <title>Tuomas Koski</title>
      <link rel="alternate" type="text/html" href="http://www.lobstermonster.org/profile/koski"/>
      <link rel="avatar" type="image/png" href="http://www.gravatar.com/avatar/a0c6e63b9b8b8d4f6faa3c9ea62f43bf.png"/>
    </activity:actor>
  </entry>
</feed>
';
        
        $expected= '<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:activity="http://activitystrea.ms/spec/1.0/" xmlns:thr="http://purl.org/syndication/thread/1.0">
  <generator uri="http://madebymonsieur.com" version="0.0.1">MiniMe - Life to XML</generator>
  <id>http://localhost/index.php?controller=profile&amp;username=user-c</id>
  <title>User C\'s Microblog</title>
  <subtitle>C Stuff</subtitle>
  <logo></logo>
  <updated>2010-08-04T09:41:16+02:00</updated>
  <author>
    <name>User C</name>
    <uri>http://localhost/index.php?controller=profile&amp;username=user-c</uri>
  </author>
  <link rel="alternate" type="text/html" href="http://localhost/index.php?controller=profile&amp;amp;username=user-c"/>
  <link rel="hub" href="http://localhost/index.php?controller=hub"/>
  <link rel="http://salmon-protocol.org/ns/salmon-replies" href="http://localhost/index.php?controller=salmon&amp;username=user-c"/>
  <link rel="self" type="application/atom+xml" href="http://localhost/index.php?controller=atom&amp;username=user-c"/>
  <activity:subject>
    <activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
    <id>http://localhost/index.php?controller=profile&amp;username=user-c</id>
    <title>User C</title>
    <link rel="alternate" type="text/html" href="http://localhost/index.php?controller=profile&amp;amp;username=user-c"/>
  </activity:subject>
  <entry>
    <id>http://identi.ca/notice/44997825</id>
    <author>
      <name>testkoski</name>
      <uri>http://identi.ca/user/209172</uri>
    </author>
    <link rel="alternate" type="text/html" href="http://identi.ca/notice/44997825"/>
    <updated>2010-08-04T08:28:08+00:00</updated>
    <title>Test.</title>
    <content type="html">Test.</content>
    <activity:actor>
      <activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
      <id>http://www.lobstermonster.org/profile/koski</id>
      <title>Tuomas Koski</title>
      <link rel="alternate" type="text/html" href="http://www.lobstermonster.org/profile/koski"/>
      <link rel="avatar" type="image/png" href="http://www.gravatar.com/avatar/a0c6e63b9b8b8d4f6faa3c9ea62f43bf.png"/>
    </activity:actor>
  </entry>
  <entry>
    <id>http://localhost/index.php?controller=atom&amp;username=koski&amp;postid=1280914748</id>
    <updated>2010-08-04T09:28:08+00:00</updated>
    <link rel="alternate" type="text/html" href="http://localhost/index.php?controller=atom&amp;username=koski&amp;postid=1280914748"/>
    <title>The first blog post</title>
    <content type="html">The first blog post</content>
    <author>
      <name>User C</name>
      <uri>http://localhost/index.php?controller=profile&amp;username=user-c</uri>
    </author>
    <activity:actor>
      <activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
      <id>http://localhost/index.php?controller=profile&amp;username=user-c</id>
      <title>User C</title>
      <link rel="alternate" type="text/html" href="http://localhost/index.php?controller=profile&amp;amp;username=user-c"/>
      <link rel="avatar" type="image/png" href="http://www.logo.here/i.jpg"/>
      <link rel="photo" type="image/png" href="http://www.logo.here/i.jpg"/>
    </activity:actor>
    <activity:verb>http://activitystrea.ms/schema/1.0/post</activity:verb>
    <activity:object>
      <activity:object-type>http://activitystrea.ms/schema/1.0/note</activity:object-type>
      <id>http://localhost/index.php?controller=atom&amp;username=koski&amp;postid=1280914748</id>
      <content type="html">The first blog post</content>
      <link rel="alternate" type="text/html" href="http://localhost/index.php?controller=atom&amp;username=koski&amp;postid=1280914748"/>
    </activity:object>
  </entry>
</feed>
';
        
        $feed = Atom_Feed::buildFromRawXML($rawXML);
        //echo $feed->asXML();
        $conf['url']['profile_highligh_post'] = "http://localhost/index.php?controller=atom&username={username}&postid={postid}";
        
        $array['id'] = Minime_HrefRenderer::getEntryLinkAlternate("koski", '1280914748', $conf);
        $array['updated'] = '2010-08-04T09:28:08+00:00';
        $array['alternate_href'] = $array['id'];
        $array['title'] = "The first blog post";
        $array['author']['uri'] = $feed->getAuthor()->getUri()->getUri();
        $array['author']['name'] = $feed->getAuthor()->getName()->getName();
        
        $entry = Atom_Entry::buildFromArray($array);
        
        // Let's create the activity actor
        $as_actor = new Activitystream_Actor();
        $as_actor->addChildElement(new Activitystream_ObjectType(Activitystream_ObjectType::TYPE_PERSON));
                
        $as_actor->addChildElement(new Atom_Entry_Id("http://localhost/index.php?controller=profile&amp;username=user-c"));
        $as_actor->addChildElement(new Atom_Entry_Title("User C"));
        $as_actor->addChildElement(new Atom_Entry_Link(Atom_Entry_Link::REL_ALTERNATE, 
                                                       Atom_Entry_Link::TYPE_TEXTHTML, 
                                                       "http://localhost/index.php?controller=profile&amp;username=user-c"));
        $as_actor->addChildElement(new Atom_Entry_Link_Avatar("http://www.logo.here/i.jpg"));
        $as_actor->addChildElement(new Atom_Entry_Link_Photo("http://www.logo.here/i.jpg"));
        
        // And let's create the activity verb
        $as_verb = new Activitystream_Verb(Activitystream_Verb::VERB_POST);
        
        $as_object = new Activitystream_Object();
        $as_object->addChildElement(new Activitystream_ObjectType(Activitystream_ObjectType::TYPE_NOTE));
        $as_object->addChildElement(new Atom_Entry_Id($array['id']));
        $as_object->addChildElement(new Atom_Entry_Content($array['title'], Atom_Entry_Content::TYPE_HTML));
        $as_object->addChildElement(new Atom_Entry_Link_AlternateHtml($array['id']));
        
        $entry->addChildElement($as_actor);
        $entry->addChildElement($as_verb);
        $entry->addChildElement($as_object);
        
        $feed->addChildElement($entry);
        $this->assertEquals($expected, $feed->asXML());
    }
    
    public function testReadFeedUnchanged() {
        $expected= '<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:activity="http://activitystrea.ms/spec/1.0/" xmlns:thr="http://purl.org/syndication/thread/1.0">
  <generator uri="http://madebymonsieur.com" version="0.0.1">MiniMe - Life to XML</generator>
  <id>http://localhost/index.php?controller=profile&amp;username=user-c</id>
  <title>User C\'s Microblog</title>
  <subtitle>C Stuff</subtitle>
  <logo></logo>
  <updated>2010-08-04T09:41:16+02:00</updated>
  <author>
    <name>User C</name>
    <uri>http://localhost/index.php?controller=profile&amp;username=user-c</uri>
  </author>
  <link rel="alternate" type="text/html" href="http://localhost/index.php?controller=profile&amp;amp;username=user-c"/>
  <link rel="hub" href="http://localhost/index.php?controller=hub"/>
  <link rel="http://salmon-protocol.org/ns/salmon-replies" href="http://localhost/index.php?controller=salmon&amp;username=user-c"/>
  <link rel="self" type="application/atom+xml" href="http://localhost/index.php?controller=atom&amp;username=user-c"/>
  <activity:subject>
    <activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
    <id>http://localhost/index.php?controller=profile&amp;username=user-c</id>
    <title>User C</title>
    <link rel="alternate" type="text/html" href="http://localhost/index.php?controller=profile&amp;amp;username=user-c"/>
  </activity:subject>
  <entry>
    <id>http://identi.ca/notice/44997825</id>
    <author>
      <name>testkoski</name>
      <uri>http://identi.ca/user/209172</uri>
    </author>
    <link rel="alternate" type="text/html" href="http://identi.ca/notice/44997825"/>
    <updated>2010-08-04T08:28:08+00:00</updated>
    <title>Test.</title>
    <content type="html">Test.</content>
    <activity:actor>
      <activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
      <id>http://www.lobstermonster.org/profile/koski</id>
      <title>Tuomas Koski</title>
      <link rel="alternate" type="text/html" href="http://www.lobstermonster.org/profile/koski"/>
      <link rel="avatar" type="image/png" href="http://www.gravatar.com/avatar/a0c6e63b9b8b8d4f6faa3c9ea62f43bf.png"/>
    </activity:actor>
  </entry>
  <entry>
    <id>http://localhost/index.php?controller=atom&amp;username=koski&amp;postid=1280914748</id>
    <author>
      <name>User C</name>
      <uri>http://localhost/index.php?controller=profile&amp;username=user-c</uri>
    </author>
    <link rel="alternate" type="text/html" href="http://localhost/index.php?controller=atom&amp;username=koski&amp;postid=1280914748"/>
    <updated>2010-08-04T09:28:08+00:00</updated>
    <title>The first blog post</title>
    <content type="html">The first blog post</content>
    <activity:actor>
      <activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
      <id>http://localhost/index.php?controller=profile&amp;username=user-c</id>
      <title>User C</title>
      <link rel="alternate" type="text/html" href="http://localhost/index.php?controller=profile&amp;amp;username=user-c"/>
      <link rel="avatar" type="image/png" href="http://www.logo.here/i.jpg"/>
    </activity:actor>
    <activity:verb>http://activitystrea.ms/schema/1.0/post</activity:verb>
    <activity:object>
      <activity:object-type>http://activitystrea.ms/schema/1.0/note</activity:object-type>
      <id>http://localhost/index.php?controller=atom&amp;username=koski&amp;postid=1280914748</id>
      <content type="html">The first blog post</content>
      <link rel="alternate" type="text/html" href="http://localhost/index.php?controller=atom&amp;username=koski&amp;postid=1280914748"/>
    </activity:object>
  </entry>
</feed>
';
        
        $feed = Atom_Feed::buildFromRawXML($expected);
        $this->assertEquals($expected, $feed->asXML());
    }
    
    /**
     */
//    public function testFailingEvanPost() {
//        $rawXML = '< ? xml version="1.0" encoding="UTF-8" ? >
//<feed xmlns="http://www.w3.org/2005/Atom" xmlns:activity="http://activitystrea.ms/spec/1.0/">
//  <generator uri="http://madebymonsieur.com" version="0.0.1">MiniMe - Life to XML</generator>
//  <id>http://www.lobstermonster.org/profile/koski</id>
//  <title>Tuomas Koski\'s OStatus Life.</title>
//  <subtitle>Microblogging from me and the people I follow. Live from this feed 24/7.</subtitle>
//  <logo>http://www.gravatar.com/avatar/a0c6e63b9b8b8d4f6faa3c9ea62f43bf.png</logo>
//  <author>
//    <name>Tuomas Koski</name>
//    <uri>http://www.lobstermonster.org/profile/koski</uri>
//  </author>
//  <link rel="alternate" type="text/html" href="http://www.lobstermonster.org/profile/koski"/>
//  <link rel="hub" href="http://www.lobstermonster.org/hub"/>
//  <link rel="http://salmon-protocol.org/ns/salmon-replies" href="http://www.lobstermonster.org/salmon/koski"/>
//  <link rel="self" type="application/atom+xml" href="http://www.lobstermonster.org/atom/koski"/>
//  <activity:subject>
//    <activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
//    <id>http://www.lobstermonster.org/profile/koski</id>
//    <title>Tuomas Koski</title>
//    <link rel="alternate" type="text/html" href="http://www.lobstermonster.org/profile/koski"/>
//    <link rel="avatar" type="image/png" href="http://www.gravatar.com/avatar/a0c6e63b9b8b8d4f6faa3c9ea62f43bf.png"/>
//  </activity:subject>
//  <entry>
//    <id>http://evan.status.net/notice/94927</id>
//    <link rel="alternate" type="text/html" href="http://evan.status.net/notice/94927"/>
//    <updated>2010-08-05T19:37:06-04:00</updated>
//    <title>The first rule of organizational design is that all organizational designs are bad.` http://ur1.ca/10hy0</title>
//    <content type="html"> The first rule of organizational design is that all organizational designs are bad.` http://ur1.ca/10hy0</content>
//    <author>
//      <name>evan</name>
//      <uri>http://evan.status.net/user/1</uri>
//    </author>
//  </entry>
//  <updated>2010-08-06T01:28:22+02:00</updated>
//</feed>';
//        //echo html_entity_decode('&ldquo;&rdquo;&mdash;&rsquo;');
//        $feed = Atom_Feed::buildFromRawXML($rawXML);
//        $this->assertEquals("", $feed->asXML());
//    }

    public function testRemoveEntryFromFeed() {
        $rawXML = '<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:activity="http://activitystrea.ms/spec/1.0/" xmlns:thr="http://purl.org/syndication/thread/1.0">
  <generator uri="http://madebymonsieur.com" version="0.0.1">MiniMe - Life to XML</generator>
  <id>http://www.lobstermonster.org/profile/koski</id>
  <title>Tuomas Koski\'s OStatus Life.</title>
  <subtitle>Microblogging from me and the people I follow. Live from this feed 24/7.</subtitle>
  <logo>http://www.gravatar.com/avatar/a0c6e63b9b8b8d4f6faa3c9ea62f43bf.png</logo>
  <updated>2010-08-05T13:53:16+00:00</updated>
  <author>
    <name>Tuomas Koski</name>
    <uri>http://www.lobstermonster.org/profile/koski</uri>
  </author>
  <link rel="alternate" type="text/html" href="http://www.lobstermonster.org/profile/koski"/>
  <link rel="hub" href="http://www.lobstermonster.org/hub"/>
  <link rel="http://salmon-protocol.org/ns/salmon-replies" href="http://www.lobstermonster.org/salmon/koski"/>
  <link rel="self" type="application/atom+xml" href="http://www.lobstermonster.org/atom/koski"/>
  <activity:subject>
    <activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
    <id>http://www.lobstermonster.org/profile/koski</id>
    <title>Tuomas Koski</title>
    <link rel="alternate" type="text/html" href="http://www.lobstermonster.org/profile/koski"/>
    <link rel="avatar" type="image/png" href="http://www.gravatar.com/avatar/a0c6e63b9b8b8d4f6faa3c9ea62f43bf.png"/>
  </activity:subject>
  <entry>
    <id>http://identi.ca/testkoski</id>
    <author>
      <name>testkoski</name>
      <uri>http://identi.ca/user/209172</uri>
    </author>
    <link rel="alternate" type="text/html" href="http://identi.ca/notice/45146741"/>
    <updated>2010-08-05T13:53:16+00:00</updated>
    <title>testkoski - Identi.ca</title>
    <content type="html">@&lt;span class="vcard"&gt;&lt;a href="http://www.lobstermonster.org/profile/koski" class="url" title="Tuomas Koski"&gt;&lt;span class="fn nickname"&gt;koski&lt;/span&gt;&lt;/a&gt;&lt;/span&gt; Welcome to feder
ate with &lt;a href="http://identi.ca/" title="http://identi.ca/" rel="external"&gt;identi.ca&lt;/a&gt; (and whole &lt;a href="http://status.net/" title="http://status.net/" rel="external"&gt;status.net&lt;/a&gt; software).</content>
  </entry>
  <entry>
    <id>http://identi.ca/notice/45156179</id>
    <author>
      <name>tkoski</name>
      <uri>http://identi.ca/user/52467</uri>
    </author>
    <link rel="alternate" type="text/html" href="http://identi.ca/notice/45156179"/>
    <updated>2010-08-05T15:38:37+00:00</updated>
    <title>Anyone following tkoski, please start following koski@lobstermonster.org as well. I\'ll be using that account way more than this one.</title>
    <content type="html">Anyone following tkoski, please start following &lt;a href="mailto:koski@lobstermonster.org" title="mailto:koski@lobstermonster.org" rel="external"&gt;koski@lobstermonster.org&lt;/a&gt; as well. I\'ll be using t
hat account way more than this one.</content>
  </entry>
  <entry>
    <id>tag:aric.status.net,2010-08-05:follow:1:43:1970-01-01T00:00:00+00:00</id>
    <author>
      <name>aric</name>
      <uri>http://aric.status.net/user/1</uri>
    </author>
    <updated>2010-08-05T17:32:45+02:00</updated>
    <title>Follow</title>
    <content type="html">aric is now following Tuomas Koski.</content>
    <activity:verb>http://activitystrea.ms/schema/1.0/follow</activity:verb>
  </entry>
</feed>
';
        
        $feed = Atom_Feed::buildFromRawXML($rawXML);
        $this->assertEquals($rawXML, $feed->asXML());
        $feed->removeEntry("http://identi.ca/notice/45156179");
        
        $expected = '<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:activity="http://activitystrea.ms/spec/1.0/" xmlns:thr="http://purl.org/syndication/thread/1.0">
  <generator uri="http://madebymonsieur.com" version="0.0.1">MiniMe - Life to XML</generator>
  <id>http://www.lobstermonster.org/profile/koski</id>
  <title>Tuomas Koski\'s OStatus Life.</title>
  <subtitle>Microblogging from me and the people I follow. Live from this feed 24/7.</subtitle>
  <logo>http://www.gravatar.com/avatar/a0c6e63b9b8b8d4f6faa3c9ea62f43bf.png</logo>
  <updated>2010-08-05T13:53:16+00:00</updated>
  <author>
    <name>Tuomas Koski</name>
    <uri>http://www.lobstermonster.org/profile/koski</uri>
  </author>
  <link rel="alternate" type="text/html" href="http://www.lobstermonster.org/profile/koski"/>
  <link rel="hub" href="http://www.lobstermonster.org/hub"/>
  <link rel="http://salmon-protocol.org/ns/salmon-replies" href="http://www.lobstermonster.org/salmon/koski"/>
  <link rel="self" type="application/atom+xml" href="http://www.lobstermonster.org/atom/koski"/>
  <activity:subject>
    <activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
    <id>http://www.lobstermonster.org/profile/koski</id>
    <title>Tuomas Koski</title>
    <link rel="alternate" type="text/html" href="http://www.lobstermonster.org/profile/koski"/>
    <link rel="avatar" type="image/png" href="http://www.gravatar.com/avatar/a0c6e63b9b8b8d4f6faa3c9ea62f43bf.png"/>
  </activity:subject>
  <entry>
    <id>http://identi.ca/testkoski</id>
    <author>
      <name>testkoski</name>
      <uri>http://identi.ca/user/209172</uri>
    </author>
    <link rel="alternate" type="text/html" href="http://identi.ca/notice/45146741"/>
    <updated>2010-08-05T13:53:16+00:00</updated>
    <title>testkoski - Identi.ca</title>
    <content type="html">@&lt;span class="vcard"&gt;&lt;a href="http://www.lobstermonster.org/profile/koski" class="url" title="Tuomas Koski"&gt;&lt;span class="fn nickname"&gt;koski&lt;/span&gt;&lt;/a&gt;&lt;/span&gt; Welcome to feder
ate with &lt;a href="http://identi.ca/" title="http://identi.ca/" rel="external"&gt;identi.ca&lt;/a&gt; (and whole &lt;a href="http://status.net/" title="http://status.net/" rel="external"&gt;status.net&lt;/a&gt; software).</content>
  </entry>
  <entry>
    <id>tag:aric.status.net,2010-08-05:follow:1:43:1970-01-01T00:00:00+00:00</id>
    <author>
      <name>aric</name>
      <uri>http://aric.status.net/user/1</uri>
    </author>
    <updated>2010-08-05T17:32:45+02:00</updated>
    <title>Follow</title>
    <content type="html">aric is now following Tuomas Koski.</content>
    <activity:verb>http://activitystrea.ms/schema/1.0/follow</activity:verb>
  </entry>
</feed>
';
        
        $this->assertEquals($expected, $feed->asXML());
    }
    
    public function testGoogleFeed() {
        $rawXML = '<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <link href="http://pubsubhubbub.appspot.com/" rel="hub"/><title type="text">Activity Stream for: dbounds</title><id>http://cliqset.com/dbounds/feed</id>

<entry xmlns:activity="http://activitystrea.ms/spec/1.0/" xmlns:service="http://activitystrea.ms/service-provider"><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total>
    <activity:verb>http://activitystrea.ms/schema/1.0/post</activity:verb>
    <published>2010-08-10T16:10:34.460Z</published>
    <title type="text">dbounds posted a note on Cliqset</title>
    <service:provider>
      <name>Cliqset</name>
      <uri>http://cliqset.com/</uri>
      <icon>http://cliqset-services.s3.amazonaws.com/cliqset.png</icon>
    </service:provider>
    <activity:object>
      <activity:object-type>http://activitystrea.ms/schema/1.0/note</activity:object-type>
      <content type="text">Busy day.</content>
    <id>tag:cliqset.com,2010-08-10:/dbounds/8l4G4D4zmBLyPQee/0</id></activity:object>
    <category term="StatusPosted" scheme="http://schemas.cliqset.com/activity/categories/1.0" label="Status Posted"/>
    <updated>2010-08-10T16:10:34.302Z</updated>
    <id>tag:cliqset.com,2010-08-10:/dbounds/8l4G4D4zmBLyPQee</id>
    <link href="http://cliqset.com/user/dbounds/8l4G4D4zmBLyPQee" type="text/xhtml" rel="alternate" title="dbounds posted a note on Cliqset"/>
    <author>
      <name>dbounds</name>
      <uri>http://cliqset.com/user/dbounds</uri>
    </author>
    <activity:actor xmlns:poco="http://portablecontacts.net/spec/1.0">
      <activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>

      <poco:name>
        <poco:givenName>Darren</poco:givenName>
        <poco:familyName>Bounds</poco:familyName>
      </poco:name>
      <link xmlns:media="http://purl.org/syndication/atommedia" href="http://dynamic.cliqset.com/avatar/dbounds?s=80" rel="avatar" media:width="80" type="image/png" media:height="80"/>
      <link xmlns:media="http://purl.org/syndication/atommedia" href="http://dynamic.cliqset.com/avatar/dbounds?s=120" rel="avatar" media:width="120" type="image/png" media:height="120"/>
      <link xmlns:media="http://purl.org/syndication/atommedia" href="http://dynamic.cliqset.com/avatar/dbounds?s=200" rel="avatar" media:width="200" type="image/png" media:height="200"/>
    <link length="0" href="http://cliqset.com/dbounds" type="text/html" rel="alternate"/><id>http://cliqset.com/dbounds</id></activity:actor>
  </entry>
<entry xmlns:activity="http://activitystrea.ms/spec/1.0/" xmlns:cs="http://schemas.cliqset.com/200909" xml:lang="en" xmlns:service="http://activitystrea.ms/service-provider"><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total>


    <summary type="html">RT @harper: Protest the death of net neutrality and make this Friday the 13th your Google Free day. Please retweet. #googlefree</summary>



    <activity:object>

      <activity:object-type>http://activitystrea.ms/schema/1.0/note</activity:object-type>

      <id>http://twitter.com/julien51/statuses/20805116194</id>

      <content type="text">RT @harper: Protest the death of net neutrality and make this Friday the 13th your Google Free day. Please retweet. #googlefree</content>

      <link href="http://twitter.com/julien51/statuses/20805116194" type="text/html" rel="alternate"/>
    <id>tag:cliqset.com,2010-08-10:/dbounds/vK0rHeLlf8ceCQee/0</id></activity:object>



    <category term="googlefree" scheme="http://schemas.cliqset.com/activity/tags/1.0" label="googlefree"/>

    <cs:properties>

      <cs:property cs:name="tweetid">20805116194</cs:property>

      <cs:property cs:name="tweeturi">http://twitter.com/julien51/statuses/20805116194</cs:property>

      <cs:property cs:name="twitterusername">julien51</cs:property>

      <cs:property cs:name="twitterid">5381582</cs:property>
    </cs:properties>






    <contributor>
      <name>Julien GENESTOUX</name>
      <uri>http://cliqset.com/user/julien</uri>
    </contributor>
    <title type="text">dbounds shared : julien posted a note on Twitter</title>
    <service:provider>
      <name>Cliqset</name>
      <uri>http://cliqset.com/</uri>
      <icon>http://cliqset-services.s3.amazonaws.com/cliqset.png</icon>
    </service:provider>
    <activity:verb>http://activitystrea.ms/schema/1.0/share</activity:verb>
    <published>2010-08-10T15:58:35.342Z</published>
    <link href="http://cliqset.com/user/julien/MjA4MDUxMTYxOTQe" type="text/xhtml" rel="via" title="julien posted a note on Twitter"/>
    <category term="StatusShared" scheme="http://schemas.cliqset.com/activity/categories/1.0" label="Status Shared"/>
    <updated>2010-08-10T15:58:35.342Z</updated>
    <id>tag:cliqset.com,2010-08-10:/dbounds/vK0rHeLlf8ceCQee</id>
    <link href="http://cliqset.com/user/dbounds/vK0rHeLlf8ceCQee" type="text/xhtml" rel="alternate" title="dbounds shared : julien posted a note on Twitter"/>
    <author>
      <name>dbounds</name>
      <uri>http://cliqset.com/user/dbounds</uri>
    </author>
    <activity:actor xmlns:poco="http://portablecontacts.net/spec/1.0">
      <activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>

      <poco:name>
        <poco:givenName>Darren</poco:givenName>
        <poco:familyName>Bounds</poco:familyName>
      </poco:name>
      <link xmlns:media="http://purl.org/syndication/atommedia" href="http://dynamic.cliqset.com/avatar/dbounds?s=80" rel="avatar" media:width="80" type="image/png" media:height="80"/>
      <link xmlns:media="http://purl.org/syndication/atommedia" href="http://dynamic.cliqset.com/avatar/dbounds?s=120" rel="avatar" media:width="120" type="image/png" media:height="120"/>
      <link xmlns:media="http://purl.org/syndication/atommedia" href="http://dynamic.cliqset.com/avatar/dbounds?s=200" rel="avatar" media:width="200" type="image/png" media:height="200"/>
    <link length="0" href="http://cliqset.com/dbounds" type="text/html" rel="alternate"/><id>http://cliqset.com/dbounds</id></activity:actor>
  </entry>
</feed>
';
        $feed = Atom_Feed::buildFromRawXML($rawXML);
        //$this->assertEquals("", $feed->asXML());  
    }
    
    public function testRemovingOfMultipleEntries() {
        $rawXML = '<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:activity="http://activitystrea.ms/spec/1.0/" xmlns:thr="http://purl.org/syndication/thread/1.0">
  <generator uri="http://madebymonsieur.com" version="0.0.1">MiniMe - Life to XML</generator>
  <id>http://www.lobstermonster.org/profile/koski</id>
  <title>Tuomas Koski\'s OStatus Life.</title>
  <subtitle>Microblogging from me and the people I follow. Live from this feed 24/7.</subtitle>
  <logo>http://www.gravatar.com/avatar/a0c6e63b9b8b8d4f6faa3c9ea62f43bf.png</logo>
  <author>
    <name>Tuomas Koski</name>
    <uri>http://www.lobstermonster.org/profile/koski</uri>
  </author>
  <link rel="alternate" type="text/html" href="http://www.lobstermonster.org/profile/koski"/>
  <link rel="hub" href="http://www.lobstermonster.org/hub"/>
  <link rel="http://salmon-protocol.org/ns/salmon-replies" href="http://www.lobstermonster.org/salmon/koski"/>
  <link rel="self" type="application/atom+xml" href="http://www.lobstermonster.org/atom/koski"/>
  <activity:subject>
    <activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
    <id>http://www.lobstermonster.org/profile/koski</id>
    <title>Tuomas Koski</title>
    <link rel="alternate" type="text/html" href="http://www.lobstermonster.org/profile/koski"/>
    <link rel="avatar" type="image/png" href="http://www.gravatar.com/avatar/a0c6e63b9b8b8d4f6faa3c9ea62f43bf.png"/>
  </activity:subject>
  <entry>
    <id>http://status.ianmcorvidae.net/notice/18348</id>
    <author>
      <name>ianmcorvidae</name>
      <uri>http://status.ianmcorvidae.net/user/1</uri>
    </author>
    <link rel="alternate" type="text/html" href="http://status.ianmcorvidae.net/notice/18348"/>
    <updated>2010-08-09T06:09:08+00:00</updated>
    <title>RT @koski I know this is a bit old but it made me smile again this morning: http://i.imgur.com/BgC3P.jpg</title>
    <content type="html">RT @&lt;span class="vcard"&gt;&lt;a href="http://www.lobstermonster.org/profile/koski" class="url" title="Tuomas Koski"&gt;&lt;span class="fn nickname"&gt;koski&lt;/span&gt;&lt;/a&gt;&lt;/span&gt; I know this is a bit old but it made me smile again this morning: &lt;a href="http://i.imgur.com/BgC3P.jpg" title="http://i.imgur.com/BgC3P.jpg" rel="external" class="attachment" id="attachment-640"&gt;http://i.imgur.com/BgC3P.jpg&lt;/a&gt;</content>
  </entry>
  <entry>
    <id>http://identi.ca/notice/45681017</id>
    <author>
      <name>tkoski</name>
      <uri>http://identi.ca/user/52467</uri>
    </author>
    <link rel="alternate" type="text/html" href="http://identi.ca/notice/45681017"/>
    <updated>2010-08-10T13:35:27+00:00</updated>
    <title>Hoi Karel! Does this work?</title>
    <content type="html">Hoi Karel! Does this work?</content>
  </entry>
  <entry>
    <id>http://identi.ca/notice/45681134</id>
    <author>
      <name>tkoski</name>
      <uri>http://identi.ca/user/52467</uri>
    </author>
    <link rel="alternate" type="text/html" href="http://identi.ca/notice/45681134"/>
    <updated>2010-08-10T13:37:01+00:00</updated>
    <title>Karel rules!</title>
    <content type="html">Karel rules!</content>
  </entry>
  <entry>
    <id>http://identi.ca/notice/45681579</id>
    <author>
      <name>gbraad</name>
      <uri>http://identi.ca/user/15178</uri>
    </author>
    <link rel="alternate" type="text/html" href="http://identi.ca/notice/45681579"/>
    <updated>2010-08-10T13:41:55+00:00</updated>
    <title>Navre (AVR) testing wanted for the !Milkymist project !navre /cc: @milkymistvj http://bit.ly/MilkymistContact</title>
    <content type="html">Navre (AVR) testing wanted for the !&lt;span class="vcard"&gt;&lt;a href="http://identi.ca/group/7177/id" class="url" title="MilkyMist (milkymist)"&gt;&lt;span class="fn nickname"&gt;Milkymist&lt;/span&gt;&lt;/a&gt;&lt;/span&gt; project !&lt;span class="vcard"&gt;&lt;a href="http://identi.ca/group/13090/id" class="url" title="Navre (navre)"&gt;&lt;span class="fn nickname"&gt;navre&lt;/span&gt;&lt;/a&gt;&lt;/span&gt; /cc: @&lt;span class="vcard"&gt;&lt;a href="http://identi.ca/user/196051" class="url" title="Milkymist"&gt;&lt;span class="fn nickname"&gt;milkymistvj&lt;/span&gt;&lt;/a&gt;&lt;/span&gt; &lt;a href="http://bit.ly/MilkymistContact" title="http://milkymist.org/resources.html" rel="external"&gt;http://bit.ly/MilkymistContact&lt;/a&gt;</content>
  </entry>
  <entry>
    <id>http://identi.ca/notice/45689157</id>
    <author>
      <name>mairin</name>
      <uri>http://identi.ca/user/3081</uri>
    </author>
    <link rel="alternate" type="text/html" href="http://identi.ca/notice/45689157"/>
    <updated>2010-08-10T15:07:48+00:00</updated>
    <title>Kernel.org planning to upgrade to !Fedora 13</title>
    <content type="html">&lt;a href="http://Kernel.org/" title="http://kernel.org/" rel="external"&gt;Kernel.org&lt;/a&gt; planning to upgrade to !&lt;span class="vcard"&gt;&lt;a href="http://identi.ca/group/168/id" class="url" title="Fedora users (fedora)"&gt;&lt;span class="fn nickname"&gt;Fedora&lt;/span&gt;&lt;/a&gt;&lt;/span&gt; 13</content>
  </entry>
  <updated>2010-08-17T10:44:39+02:00</updated>
</feed>
';     

        $leave = 2;
        $feed = Atom_Feed::buildFromRawXML($rawXML);
        $this->assertEquals(5, count($feed->getEntries()));
        
        $entries = $feed->getEntries();
        
        if( !(count($entries) <= $leave) ) {
            $entries = array_slice($entries, $leave);
            foreach ($entries as $entry) {
                $feed->removeEntry($entry->getId()->getId());    
            }
            
        }
        $this->assertEquals(2, count($feed->getEntries()));
        
        $expected = $rawXML = '<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:activity="http://activitystrea.ms/spec/1.0/" xmlns:thr="http://purl.org/syndication/thread/1.0">
  <generator uri="http://madebymonsieur.com" version="0.0.1">MiniMe - Life to XML</generator>
  <id>http://www.lobstermonster.org/profile/koski</id>
  <title>Tuomas Koski\'s OStatus Life.</title>
  <subtitle>Microblogging from me and the people I follow. Live from this feed 24/7.</subtitle>
  <logo>http://www.gravatar.com/avatar/a0c6e63b9b8b8d4f6faa3c9ea62f43bf.png</logo>
  <updated>2010-08-17T10:44:39+02:00</updated>
  <author>
    <name>Tuomas Koski</name>
    <uri>http://www.lobstermonster.org/profile/koski</uri>
  </author>
  <link rel="alternate" type="text/html" href="http://www.lobstermonster.org/profile/koski"/>
  <link rel="hub" href="http://www.lobstermonster.org/hub"/>
  <link rel="http://salmon-protocol.org/ns/salmon-replies" href="http://www.lobstermonster.org/salmon/koski"/>
  <link rel="self" type="application/atom+xml" href="http://www.lobstermonster.org/atom/koski"/>
  <activity:subject>
    <activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
    <id>http://www.lobstermonster.org/profile/koski</id>
    <title>Tuomas Koski</title>
    <link rel="alternate" type="text/html" href="http://www.lobstermonster.org/profile/koski"/>
    <link rel="avatar" type="image/png" href="http://www.gravatar.com/avatar/a0c6e63b9b8b8d4f6faa3c9ea62f43bf.png"/>
  </activity:subject>
  <entry>
    <id>http://identi.ca/notice/45681579</id>
    <author>
      <name>gbraad</name>
      <uri>http://identi.ca/user/15178</uri>
    </author>
    <link rel="alternate" type="text/html" href="http://identi.ca/notice/45681579"/>
    <updated>2010-08-10T13:41:55+00:00</updated>
    <title>Navre (AVR) testing wanted for the !Milkymist project !navre /cc: @milkymistvj http://bit.ly/MilkymistContact</title>
    <content type="html">Navre (AVR) testing wanted for the !&lt;span class="vcard"&gt;&lt;a href="http://identi.ca/group/7177/id" class="url" title="MilkyMist (milkymist)"&gt;&lt;span class="fn nickname"&gt;Milkymist&lt;/span&gt;&lt;/a&gt;&lt;/span&gt; project !&lt;span class="vcard"&gt;&lt;a href="http://identi.ca/group/13090/id" class="url" title="Navre (navre)"&gt;&lt;span class="fn nickname"&gt;navre&lt;/span&gt;&lt;/a&gt;&lt;/span&gt; /cc: @&lt;span class="vcard"&gt;&lt;a href="http://identi.ca/user/196051" class="url" title="Milkymist"&gt;&lt;span class="fn nickname"&gt;milkymistvj&lt;/span&gt;&lt;/a&gt;&lt;/span&gt; &lt;a href="http://bit.ly/MilkymistContact" title="http://milkymist.org/resources.html" rel="external"&gt;http://bit.ly/MilkymistContact&lt;/a&gt;</content>
  </entry>
  <entry>
    <id>http://identi.ca/notice/45689157</id>
    <author>
      <name>mairin</name>
      <uri>http://identi.ca/user/3081</uri>
    </author>
    <link rel="alternate" type="text/html" href="http://identi.ca/notice/45689157"/>
    <updated>2010-08-10T15:07:48+00:00</updated>
    <title>Kernel.org planning to upgrade to !Fedora 13</title>
    <content type="html">&lt;a href="http://Kernel.org/" title="http://kernel.org/" rel="external"&gt;Kernel.org&lt;/a&gt; planning to upgrade to !&lt;span class="vcard"&gt;&lt;a href="http://identi.ca/group/168/id" class="url" title="Fedora users (fedora)"&gt;&lt;span class="fn nickname"&gt;Fedora&lt;/span&gt;&lt;/a&gt;&lt;/span&gt; 13</content>
  </entry>
</feed>
';     
        $this->assertEquals($expected, $feed->asXML());
    }
    
    public function testAddingEntrySuccesfully() {
                $rawXML = '<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:activity="http://activitystrea.ms/spec/1.0/" xmlns:thr="http://purl.org/syndication/thread/1.0">
  <generator uri="http://madebymonsieur.com" version="0.0.1">MiniMe - Life to XML</generator>
  <id>http://www.lobstermonster.org/profile/koski</id>
  <title>Tuomas Koski\'s OStatus Life.</title>
  <subtitle>Microblogging from me and the people I follow. Live from this feed 24/7.</subtitle>
  <logo>http://www.gravatar.com/avatar/a0c6e63b9b8b8d4f6faa3c9ea62f43bf.png</logo>
  <updated>2010-08-05T13:53:16+00:00</updated>
  <author>
    <name>Tuomas Koski</name>
    <uri>http://www.lobstermonster.org/profile/koski</uri>
  </author>
  <link rel="alternate" type="text/html" href="http://www.lobstermonster.org/profile/koski"/>
  <link rel="hub" href="http://www.lobstermonster.org/hub"/>
  <link rel="http://salmon-protocol.org/ns/salmon-replies" href="http://www.lobstermonster.org/salmon/koski"/>
  <link rel="self" type="application/atom+xml" href="http://www.lobstermonster.org/atom/koski"/>
  <activity:subject>
    <activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
    <id>http://www.lobstermonster.org/profile/koski</id>
    <title>Tuomas Koski</title>
    <link rel="alternate" type="text/html" href="http://www.lobstermonster.org/profile/koski"/>
    <link rel="avatar" type="image/png" href="http://www.gravatar.com/avatar/a0c6e63b9b8b8d4f6faa3c9ea62f43bf.png"/>
  </activity:subject>
  <entry>
    <id>http://identi.ca/testkoski</id>
    <author>
      <name>testkoski</name>
      <uri>http://identi.ca/user/209172</uri>
    </author>
    <link rel="alternate" type="text/html" href="http://identi.ca/notice/45146741"/>
    <updated>2010-08-05T13:53:16+00:00</updated>
    <title>testkoski - Identi.ca</title>
    <content type="html">@&lt;span class="vcard"&gt;&lt;a href="http://www.lobstermonster.org/profile/koski" class="url" title="Tuomas Koski"&gt;&lt;span class="fn nickname"&gt;koski&lt;/span&gt;&lt;/a&gt;&lt;/span&gt; Welcome to feder
ate with &lt;a href="http://identi.ca/" title="http://identi.ca/" rel="external"&gt;identi.ca&lt;/a&gt; (and whole &lt;a href="http://status.net/" title="http://status.net/" rel="external"&gt;status.net&lt;/a&gt; software).</content>
  </entry>
  <entry>
    <id>http://identi.ca/notice/45156179</id>
    <author>
      <name>tkoski</name>
      <uri>http://identi.ca/user/52467</uri>
    </author>
    <link rel="alternate" type="text/html" href="http://identi.ca/notice/45156179"/>
    <updated>2010-08-05T15:38:37+00:00</updated>
    <title>Anyone following tkoski, please start following koski@lobstermonster.org as well. I\'ll be using that account way more than this one.</title>
    <content type="html">Anyone following tkoski, please start following &lt;a href="mailto:koski@lobstermonster.org" title="mailto:koski@lobstermonster.org" rel="external"&gt;koski@lobstermonster.org&lt;/a&gt; as well. I\'ll be using t
hat account way more than this one.</content>
  </entry>
  <entry>
    <id>tag:aric.status.net,2010-08-05:follow:1:43:1970-01-01T00:00:00+00:00</id>
    <author>
      <name>aric</name>
      <uri>http://aric.status.net/user/1</uri>
    </author>
    <updated>2010-08-05T17:32:45+02:00</updated>
    <title>Follow</title>
    <content type="html">aric is now following Tuomas Koski.</content>
    <activity:verb>http://activitystrea.ms/schema/1.0/follow</activity:verb>
  </entry>
</feed>
';
        
        $rawSalmonEntry = '<?xml version="1.0" encoding="UTF-8"?>
<entry xmlns="http://www.w3.org/2005/Atom" xmlns:thr="http://purl.org/syndication/thread/1.0">
  <id>http://identi.ca/mairin</id>
  <author>
    <name>mairin</name>
    <uri>http://identi.ca/user/3081</uri>
  </author>
  <link rel="alternate" type="text/html" href="http://identi.ca/notice/45263127"/>
  <updated>2010-08-06T14:40:22+00:00</updated>
  <title>Máirín - Identi.ca</title>
  <content type="html">@&lt;span class="vcard"&gt;&lt;a href="http://www.lobstermonster.org/profile/koski" class="url" title="Tuomas Koski"&gt;&lt;span class="fn nickname"&gt;koski&lt;/span&gt;&lt;/a&gt;&lt;/span&gt; both!</content>
  <activity:actor>
    <activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
    <id>http://identi.ca/user/3081</id>
    <title>Máirín</title>
    <link rel="alternate" type="text/html" href="http://identi.ca/mairin"/>
  </activity:actor>
  <thr:in-reply-to ref="mimime:1281104680" href="http://identi.ca/notice/45262687"/>
</entry>
'; 
                
        $feed = Atom_Feed::buildFromRawXML($rawXML);
        $entry = Atom_Entry::buildFromRawXML($rawSalmonEntry);
        
        $this->assertTrue($feed->addEntry($entry));
        
        $expected = '<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:activity="http://activitystrea.ms/spec/1.0/" xmlns:thr="http://purl.org/syndication/thread/1.0">
  <generator uri="http://madebymonsieur.com" version="0.0.1">MiniMe - Life to XML</generator>
  <id>http://www.lobstermonster.org/profile/koski</id>
  <title>Tuomas Koski\'s OStatus Life.</title>
  <subtitle>Microblogging from me and the people I follow. Live from this feed 24/7.</subtitle>
  <logo>http://www.gravatar.com/avatar/a0c6e63b9b8b8d4f6faa3c9ea62f43bf.png</logo>
  <updated>2010-08-05T13:53:16+00:00</updated>
  <author>
    <name>Tuomas Koski</name>
    <uri>http://www.lobstermonster.org/profile/koski</uri>
  </author>
  <link rel="alternate" type="text/html" href="http://www.lobstermonster.org/profile/koski"/>
  <link rel="hub" href="http://www.lobstermonster.org/hub"/>
  <link rel="http://salmon-protocol.org/ns/salmon-replies" href="http://www.lobstermonster.org/salmon/koski"/>
  <link rel="self" type="application/atom+xml" href="http://www.lobstermonster.org/atom/koski"/>
  <activity:subject>
    <activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
    <id>http://www.lobstermonster.org/profile/koski</id>
    <title>Tuomas Koski</title>
    <link rel="alternate" type="text/html" href="http://www.lobstermonster.org/profile/koski"/>
    <link rel="avatar" type="image/png" href="http://www.gravatar.com/avatar/a0c6e63b9b8b8d4f6faa3c9ea62f43bf.png"/>
  </activity:subject>
  <entry>
    <id>http://identi.ca/testkoski</id>
    <author>
      <name>testkoski</name>
      <uri>http://identi.ca/user/209172</uri>
    </author>
    <link rel="alternate" type="text/html" href="http://identi.ca/notice/45146741"/>
    <updated>2010-08-05T13:53:16+00:00</updated>
    <title>testkoski - Identi.ca</title>
    <content type="html">@&lt;span class="vcard"&gt;&lt;a href="http://www.lobstermonster.org/profile/koski" class="url" title="Tuomas Koski"&gt;&lt;span class="fn nickname"&gt;koski&lt;/span&gt;&lt;/a&gt;&lt;/span&gt; Welcome to feder
ate with &lt;a href="http://identi.ca/" title="http://identi.ca/" rel="external"&gt;identi.ca&lt;/a&gt; (and whole &lt;a href="http://status.net/" title="http://status.net/" rel="external"&gt;status.net&lt;/a&gt; software).</content>
  </entry>
  <entry>
    <id>http://identi.ca/notice/45156179</id>
    <author>
      <name>tkoski</name>
      <uri>http://identi.ca/user/52467</uri>
    </author>
    <link rel="alternate" type="text/html" href="http://identi.ca/notice/45156179"/>
    <updated>2010-08-05T15:38:37+00:00</updated>
    <title>Anyone following tkoski, please start following koski@lobstermonster.org as well. I\'ll be using that account way more than this one.</title>
    <content type="html">Anyone following tkoski, please start following &lt;a href="mailto:koski@lobstermonster.org" title="mailto:koski@lobstermonster.org" rel="external"&gt;koski@lobstermonster.org&lt;/a&gt; as well. I\'ll be using t
hat account way more than this one.</content>
  </entry>
  <entry>
    <id>tag:aric.status.net,2010-08-05:follow:1:43:1970-01-01T00:00:00+00:00</id>
    <author>
      <name>aric</name>
      <uri>http://aric.status.net/user/1</uri>
    </author>
    <updated>2010-08-05T17:32:45+02:00</updated>
    <title>Follow</title>
    <content type="html">aric is now following Tuomas Koski.</content>
    <activity:verb>http://activitystrea.ms/schema/1.0/follow</activity:verb>
  </entry>
  <entry>
    <id>http://identi.ca/mairin</id>
    <author>
      <name>mairin</name>
      <uri>http://identi.ca/user/3081</uri>
    </author>
    <link rel="alternate" type="text/html" href="http://identi.ca/notice/45263127"/>
    <updated>2010-08-06T14:40:22+00:00</updated>
    <title>Máirín - Identi.ca</title>
    <content type="html">@&lt;span class="vcard"&gt;&lt;a href="http://www.lobstermonster.org/profile/koski" class="url" title="Tuomas Koski"&gt;&lt;span class="fn nickname"&gt;koski&lt;/span&gt;&lt;/a&gt;&lt;/span&gt; both!</content>
    <thr:in-reply-to ref="mimime:1281104680" href="http://identi.ca/notice/45262687"/>
  </entry>
</feed>
';
        
        $this->assertEquals($expected, $feed->asXML());
    }
    
    public function testAddingDuplicateEntry() {
        $rawXML = '<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:activity="http://activitystrea.ms/spec/1.0/" xmlns:thr="http://purl.org/syndication/thread/1.0">
  <generator uri="http://madebymonsieur.com" version="0.0.1">MiniMe - Life to XML</generator>
  <id>http://www.lobstermonster.org/profile/koski</id>
  <title>Tuomas Koski\'s OStatus Life.</title>
  <subtitle>Microblogging from me and the people I follow. Live from this feed 24/7.</subtitle>
  <logo>http://www.gravatar.com/avatar/a0c6e63b9b8b8d4f6faa3c9ea62f43bf.png</logo>
  <updated>2010-08-05T13:53:16+00:00</updated>
  <author>
    <name>Tuomas Koski</name>
    <uri>http://www.lobstermonster.org/profile/koski</uri>
  </author>
  <link rel="alternate" type="text/html" href="http://www.lobstermonster.org/profile/koski"/>
  <link rel="hub" href="http://www.lobstermonster.org/hub"/>
  <link rel="http://salmon-protocol.org/ns/salmon-replies" href="http://www.lobstermonster.org/salmon/koski"/>
  <link rel="self" type="application/atom+xml" href="http://www.lobstermonster.org/atom/koski"/>
  <activity:subject>
    <activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
    <id>http://www.lobstermonster.org/profile/koski</id>
    <title>Tuomas Koski</title>
    <link rel="alternate" type="text/html" href="http://www.lobstermonster.org/profile/koski"/>
    <link rel="avatar" type="image/png" href="http://www.gravatar.com/avatar/a0c6e63b9b8b8d4f6faa3c9ea62f43bf.png"/>
  </activity:subject>
  <entry>
    <id>http://identi.ca/testkoski</id>
    <author>
      <name>testkoski</name>
      <uri>http://identi.ca/user/209172</uri>
    </author>
    <link rel="alternate" type="text/html" href="http://identi.ca/notice/45146741"/>
    <updated>2010-08-05T13:53:16+00:00</updated>
    <title>testkoski - Identi.ca</title>
    <content type="html">@&lt;span class="vcard"&gt;&lt;a href="http://www.lobstermonster.org/profile/koski" class="url" title="Tuomas Koski"&gt;&lt;span class="fn nickname"&gt;koski&lt;/span&gt;&lt;/a&gt;&lt;/span&gt; Welcome to feder
ate with &lt;a href="http://identi.ca/" title="http://identi.ca/" rel="external"&gt;identi.ca&lt;/a&gt; (and whole &lt;a href="http://status.net/" title="http://status.net/" rel="external"&gt;status.net&lt;/a&gt; software).</content>
  </entry>
  <entry>
    <id>http://identi.ca/notice/45156179</id>
    <author>
      <name>tkoski</name>
      <uri>http://identi.ca/user/52467</uri>
    </author>
    <link rel="alternate" type="text/html" href="http://identi.ca/notice/45156179"/>
    <updated>2010-08-05T15:38:37+00:00</updated>
    <title>Anyone following tkoski, please start following koski@lobstermonster.org as well. I\'ll be using that account way more than this one.</title>
    <content type="html">Anyone following tkoski, please start following &lt;a href="mailto:koski@lobstermonster.org" title="mailto:koski@lobstermonster.org" rel="external"&gt;koski@lobstermonster.org&lt;/a&gt; as well. I\'ll be using t
hat account way more than this one.</content>
  </entry>
  <entry>
    <id>tag:aric.status.net,2010-08-05:follow:1:43:1970-01-01T00:00:00+00:00</id>
    <author>
      <name>aric</name>
      <uri>http://aric.status.net/user/1</uri>
    </author>
    <updated>2010-08-05T17:32:45+02:00</updated>
    <title>Follow</title>
    <content type="html">aric is now following Tuomas Koski.</content>
    <activity:verb>http://activitystrea.ms/schema/1.0/follow</activity:verb>
  </entry>
  <entry>
    <id>http://identi.ca/mairin</id>
    <author>
      <name>mairin</name>
      <uri>http://identi.ca/user/3081</uri>
    </author>
    <link rel="alternate" type="text/html" href="http://identi.ca/notice/45263127"/>
    <updated>2010-08-06T14:40:22+00:00</updated>
    <title>Máirín - Identi.ca</title>
    <content type="html">@&lt;span class="vcard"&gt;&lt;a href="http://www.lobstermonster.org/profile/koski" class="url" title="Tuomas Koski"&gt;&lt;span class="fn nickname"&gt;koski&lt;/span&gt;&lt;/a&gt;&lt;/span&gt; both!</content>
    <thr:in-reply-to ref="mimime:1281104680" href="http://identi.ca/notice/45262687"/>
  </entry>
</feed>
';
        
        $rawSalmonEntry = '<?xml version="1.0" encoding="UTF-8"?>
<entry xmlns="http://www.w3.org/2005/Atom" xmlns:thr="http://purl.org/syndication/thread/1.0">
  <id>http://identi.ca/mairin</id>
  <author>
    <name>mairin</name>
    <uri>http://identi.ca/user/3081</uri>
  </author>
  <link rel="alternate" type="text/html" href="http://identi.ca/notice/45263127"/>
  <updated>2010-08-06T14:40:22+00:00</updated>
  <title>Máirín - Identi.ca</title>
  <content type="html">@&lt;span class="vcard"&gt;&lt;a href="http://www.lobstermonster.org/profile/koski" class="url" title="Tuomas Koski"&gt;&lt;span class="fn nickname"&gt;koski&lt;/span&gt;&lt;/a&gt;&lt;/span&gt; both!</content>
  <activity:actor>
    <activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
    <id>http://identi.ca/user/3081</id>
    <title>Máirín</title>
    <link rel="alternate" type="text/html" href="http://identi.ca/mairin"/>
  </activity:actor>
  <thr:in-reply-to ref="mimime:1281104680" href="http://identi.ca/notice/45262687"/>
</entry>
'; 
                
        $feed = Atom_Feed::buildFromRawXML($rawXML);
        $entry = Atom_Entry::buildFromRawXML($rawSalmonEntry);
        
        $this->assertFalse($feed->addEntry($entry));
        
        $this->assertEquals($rawXML, $feed->asXML());
    }
}